(defun trianglep (x)
  (/ (- (sqrt (+ 1 (* 8 x))) 1) 2))
  
(defun trianglep(n)
  (let ((x (/ (1- (sqrt (1+ (* 8 n)))) 2)))
    (zerop (- x (floor x)))))

(defun index-char (c)
  (- (char-code c) 64))

(defun sum-word (w)
  (loop for c across w summing (index-char c)))

(defun read-words()
  (with-open-file (stream "/home/irimiad/lisp/words.txt")
    (read stream)))

(defun probl42 ()
  (length (delete-if-not #'trianglep (mapcar #'sum-word (read-words)))))